<template>
    <el-container class="contain">
      <el-container>
        <el-aside width="200px">
          <el-menu :default-openeds="['1']">
            <el-submenu index="1">
                <template #title>视频分类</template>
              <el-menu-item  style="background-color: rgba(126, 175, 151, 0.132) ;font-size: 15px;font-weight: bold; " index="1-1">娱乐视频</el-menu-item>
              <el-menu-item  style="background-color: rgba(126, 175, 151, 0.132) ;font-size: 15px;font-weight: bold; " index="1-2">教育视频</el-menu-item>
              <el-menu-item  style="background-color: rgba(126, 175, 151, 0.132) ;font-size: 15px;font-weight: bold;" index="1-3">其他</el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <el-form :model="videoForm" label-width="80px">
            <el-form-item label="视频标题">
              <el-input v-model="videoForm.title" placeholder="请输入视频标题"></el-input>
            </el-form-item>
            <el-form-item label="视频描述">
              <el-input type="textarea" v-model="videoForm.description" placeholder="请输入视频描述"></el-input>
            </el-form-item>
            <el-form-item label="视频文件">
              <el-upload
                class="upload-demo"
                action="#"
                :on-change="handleVideoUpload"
                :before-upload="beforeVideoUpload"
                :limit="1"
                :file-list="videoFileList"
              >
                <el-button size="small" type="primary">点击上传视频</el-button>
              </el-upload>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="saveVideo">保存视频信息</el-button>
            </el-form-item>
          </el-form>
          <el-table :data="videoList" style="width: 100%; margin-top: 20px;">
            <el-table-column prop="title" label="标题"></el-table-column>
            <el-table-column prop="description" label="描述"></el-table-column>
            <el-table-column label="操作">
              <template  v-slot="scope">
                <el-button type="text" @click="playVideo(scope.row)">播放</el-button>
                <el-button type="text" @click="deleteVideo(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-main>
      </el-container>
      <el-footer>版权所有 @智思云有限公司</el-footer>
    </el-container>
  </template>
  
  <script>
  export default {
    data() {
      return {
        videoForm: {
          title: '',
          description: '',
        },
        videoFileList: [],
        videoList: []
      };
    },
    methods: {
      handleVideoUpload(file, fileList) {
        this.videoFileList = fileList;
      },
      beforeVideoUpload(file) {
        const isVideo = file.type.startsWith('video/');
        if (!isVideo) {
          this.$message.error('只能上传视频文件');
          return false;
        }
        return true;
      },
      saveVideo() {
        if (this.videoForm.title && this.videoFileList.length > 0) {
          const newVideo = {
           ...this.videoForm,
            file: this.videoFileList[0]
          };
          this.videoList.push(newVideo);
          this.videoForm.title = '';
          this.videoForm.description = '';
          this.videoFileList = [];
          this.$message.success('视频信息保存成功');
        } else {
          this.$message.warning('请填写标题并上传视频文件');
        }
      },
      playVideo(video) {
        // 这里可以添加播放视频的逻辑，比如使用 HTML5 video 标签等，此处仅模拟
        this.$message.info(`正在播放视频: ${video.title}`);
      },
      deleteVideo(video) {
        const index = this.videoList.findIndex(v => v === video);
        if (index!== -1) {
          this.videoList.splice(index, 1);
          this.$message.success('视频已删除');
        }
      }
    }
  };
  </script>
  
  <style scoped>
  .contain{
    height: auto;
    width: 1345px;
    margin-left: 180px;
    background-color: rgba(126, 175, 151, 0.132);
  }
  .upload-demo {
    margin-bottom: 10px;
  }
  </style>